package com.control.servlet;

import com.dao.UserDao;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017/5/23.
 */
public class RegisterServlet extends HttpServlet {

    UserDao userDao = new UserDao();

    public void init() throws ServletException {
        super.init();
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        int boo = userDao.writeUsers(req.getParameter("phoneNumber"),req.getParameter("name"),req.getParameter("password"));

        if(boo==0){
            String tip="注册失败";
            req.setAttribute("tip", tip);
            RequestDispatcher dispatcher = req.getRequestDispatcher("/jsp/RegisterActivity.jsp");
            dispatcher.forward(req, resp);
        }
        else {
            String tip="注册成功";
            req.setAttribute("tip", tip);
            RequestDispatcher dispatcher = req.getRequestDispatcher("/jsp/RegisterActivity.jsp");
            dispatcher.forward(req, resp);
        }
    }


}
